Start-up ad
Volume Number: 1
Issue Number: 3
Column Tag: ASSEMBLY
Start-up ad
By David E. Smith
Corvus called the other day and said they were sending 20 megabyte hard disks to
various dealers and asked if I would like to put something about MacTutor on them. The
problem was, they needed it the next day! So by 3 in the morning I had my double
clickable start-up ad ready to express mail for the Corvus sampler. Thinking others
might appreciate this little gem, I’ve used it as the basis for my column this month. It
combines our application shell program from the December issue with our icon
converter program from last month’s issue, with some new material on menus and
events.
WHAT THIS PROGRAM DOES
What we have here is a simple start-up program that can be set by the finder
option as the program that gets executed when the disk first boots up. The program
opens a window and draws an advertisment for MacTutor, as shown above in figure 1.
When the close box is clicked, the finder is called. Such a program can be useful for the
front end of your product development disk as a catchy way of introducing your product
when the disk is booted up. You can modify the text to advertise your product, or make
a clickable birthday card for your favorite Mac hacker. I gave a Mac Disk to a friend
for Christmas and included this program with modified text to wish him a Merry
Christmas everytime he started up his computer.
TOOLBOX FEATURES
Our program may seem simple in operation, but it’s already complex in toolbox
features as listed below:
1. Drag window capability with window updating after drag.
2. Clickable close box exit.
3. Standard menu bar with apple, file and edit menus enabled.
4. Quit command in the file menu as an alternate return to the finder.
5. Text and box drawing using quickdraw.
Although the apple and edit pop-up menus are implemented, the support code for
them is not here, so full support of the desk accesories will have to wait until next
month. Everything required for a standard Macintosh program is here except text
editing support, which is required for cut and paste. Only the quit option in the file
menu actually does something. What we want to concentrate on here is the menu bar
set-up.Then it is a minor problem to complete the stub routines to handle the
individual apple and edit menu functions.
MENUS AS RESOURCES
As we noted last month, resources suffer from almost no documentation and this
includes menus as resources. Another problem is that there are several ways to create
and maintain menus. They can be created from the program itself, or read in from a
resource file. The resource file option can be either created using the RMaker,
resource editor if it ever shows up, or by using the assembler. When creating menus
from program code, the combination _NewMenu, _AppendMenu, and _InsertMenu
traps are used. The _AppendMenu trap reads in the menu information from the local
data area at the end of your program code, and the format of the menu items is well
documented in the IM docs in the Menu Manager section. In fact, you can easily build
your own RMaker using the append menu trap.
APPEND MENU FORMAT
; This commmented code shows how you
; would do menus using in line code
; instead of resources. Place this code
; in your menu set-up routine.
PEA APPLEMENU ;menu set-up in code
_NewMenu ;make new menu
MOVE.L (SP),D7 ;save menu handle
;keep on stack
PEA APPLEMENUITEMS ;apple menu items
_AppendMenu ;add to apple menu
MOVE.L D7,-(SP) ;menu handle
CLR.W -(SP) ;add to end
_InsertMenu ;insert menu items
; This commented code shows how you would
; set up resources in code for use with
; _AppendMenu instead of using a resource
; file with _GetRMenu. Place this section
; in your data block.
;
APPLEMENU:
DC.B 1
DC.B 20 ;apple symbol title
DC.B 0
APPLEMENUITEMS:
DC.B 21
DC.B ‘ABOUT THIS PROGRAM...’
DC.B 0
; The remaining menu items would be
; desk accesories, which are added to
; this menu with another trap call.
Menu items from Resources
The reason for going through the above formats for using the append trap is
because we DID NOT use it in our program! Instead, we used resources to define the
menu and menu items and the _GetRMenu trap to read in the menu resource and set-up
the menu bar. The resources can be created either by the RMaker utility, which is well
documented, at least for making menus, or by the assembler, which is not documented
at all and is not the same format as the RMaker input syntax. After much trial and
error I finally got the assembled resource file to work. It seems the assembler creates
the binary format of each resource exactly as it is described in the IM docs. The
trouble is, not all of the resources have their internal format documented. It is my
guess that the RMaker program takes a high level description of the menu resources
and translates that description into the same binary format. So in a sense, using the
assembler meant we were our own RMaker!
Event Processing
The next major addition to this program is the event processing. Our event loop